package com.corn.turorial.spring.actuator;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2021/2/4 16:17
 */

@Endpoint(id = "myEndPoint")
@Component
public class MyEndpoint {

    private static final AtomicInteger counter = new AtomicInteger();

    private static final AtomicInteger deCounter = new AtomicInteger(10000);


    @ReadOperation
    public Map<String, Object> getInfo() {
        Map<String, Object> result = new HashMap<>();
        result.put("counter", counter.get());
        result.put("deCounter", deCounter.get());
        return result;
    }

    @WriteOperation
    public void updateInfo() {
        counter.incrementAndGet();
        deCounter.decrementAndGet();
    }

}
